<%@page import="com.situ.mvc.entity.User"%>
<%@page import="com.situ.mvc.entity.PageBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.mvc.entity.Student"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<%-- ${list} --%>
	<%-- ${requestScope.list} --%>
	<form action="${pageContext.request.contextPath}/student?method=search" method="post">
		名字：<input type="text" name="searchName"/>
		<input type="submit" value="搜索"/>
	</form>
	<a onclick="insert()" class="btn btn-success">添加</a>
	<a href="${pageContext.request.contextPath}/online_user_list.jsp" class="btn btn-success">在线用户列表</a>
	欢迎：${user.name}
	<a href="/SpringWeb/loginServlet/logout.action">注销</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>年龄</td>
			<td>性别</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageBean.list}" var="student">
			<tr>
				<td>${student.id}</td>
				<td>${student.name}</td>
				<td>${student.age}</td>
				<td>${student.gender}</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${student.id})">删除</a></td>
				<td><a onclick="toupdate(${student.id})" class="btn btn-success">修改</a></td>
				<%-- <td><a href="${pageContext.request.contextPath}/student/toUpdate.action?id=${student.id}">修改</a></td> --%>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	     <!-- 上一页开始 -->
	     <c:if test="${pageBean.pageNo==1}">
	     	<li class="disabled">
	      	   <a href="#" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		       </a>
		     </li>
	     </c:if>
	     <c:if test="${pageBean.pageNo!=1}">
	     	<li>
		      <a href="${pageContext.request.contextPath}/student/pageList.action?pageNo=${pageBean.pageNo-1}" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
	     </c:if>
	       <!-- 上一页结束-->
	     <c:forEach begin="1" end="${pageBean.totalPage}" var="i">
	     	<c:if test="${pageBean.pageNo==i}">
	     		<li class="active"><a href="#">${i}</a></li>
	     	</c:if>
	     	<c:if test="${pageBean.pageNo!=i}">
	     		<li><a href="${pageContext.request.contextPath}/student/pageList.action?pageNo=${i}">${i}</a></li>
	     	</c:if>
	     </c:forEach>
	     
	    <li>
	      <a href="${pageContext.request.contextPath}/student/pageList.action?pageNo=${pageBean.pageNo+1}" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	    </li>
	  </ul>
	</nav>
	 <script src="${pageContext.request.contextPath}/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/lib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/lib/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/lib/util.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function deleteById(id) {
			/*var isDel = confirm("您确认要删除么？");
			if (isDel) {
				location.href = "/JavaWeb1907/student?method=deleteById&id=" + id;
			}*/
			
			layer.confirm(
				"您确认要删除么？",
				function(index) {
					console.log(index);
					$.post(
						"${pageContext.request.contextPath}/student/deleteById.action?id=" + id,
						function(jsonObj){
							if(jsonObj.code == util.SUCCESS) {
								mylayer.successMsg(jsonObj.msg);
								location.reload();
							} else {
								mylayer.errorMsg(jsonObj.msg);
							}
						},
						"json"
					);
				}
			);
		}
		
		function insert() {
			layer.open({
				type : 2, // iframe
				title : "添加学生",
				area : ["300px", "200px"],
				content : "${pageContext.request.contextPath}/student/getInsertPage.action"
			});
		}
		function toupdate(id) {
			layer.open({
				type : 2, // iframe
				title : "添加学生",
				area : ["400px", "300px"],
				content : "${pageContext.request.contextPath}/student/toUpdate.action?id="+id
			});
		}
	</script>
</body>
</html>